package Text_49;

public class Code {

	public static void main(String[] args) {
		  Driver d1 = new Driver("张三",22);
	        Vehicle v = new Car();
	        Vehicle v2 = new Motorcycle();
	        d1.drive(v,33);
	        d1.stop(v2) ;
	    }
	}
	interface Vehicle{
	    void beDriven(double speed);
	    void beStopped();
	}
	class Car implements Vehicle {

	    @Override
	    public void beDriven(double speed) {
	        System.out.println(this.toString()+"以时速"+speed+"公里每小时的速度行驶");
	    }

	    @Override
	    public void beStopped() {
	        System.out.println(this.toString()+"停了下来");
	    }

	    @Override
	    public String toString() {
	        return "汽车";
	    }
	}
	class Motorcycle implements Vehicle{

	    @Override
	    public void beDriven(double speed) {
	        System.out.println(this.toString()+"以时速"+speed+"公里每小时的速度行驶");
	    }

	    @Override
	    public void beStopped() {
	        System.out.println(this.toString()+"停了下来");
	    }

	    @Override
	    public String toString() {
	        return "摩托车";
	    }
	}
	class Driver{
	    private String name ;
	    private int age;

	    public Driver() {
	    }

	    public Driver(String name, int age) {
	        this.name = name;
	        this.age = age;
	    }
	    public String getName() {
	        return name;
	    }

	    public void setName(String name) {
	        this.name = name;
	    }

	    public int getAge() {
	        return age;
	    }
	    public void setAge(int age) {
	        this.age = age;
	    }
	    public String toString() {
	        return "Driver{name = " + name + ", age = " + age + "}";
	    }
	    public void drive(Vehicle vehicle,double speed){
	        System.out.println(age+"岁的驾驶员"+name+"正在开"+vehicle.toString());
	        vehicle.beDriven(speed);
	    }
	    public void stop (Vehicle vehicle){
	        System.out.println(age+"岁的驾驶员"+name+"踩了踩刹车");
	        vehicle.beStopped();

	}

}
